package cn.isjinhao.crws.sql.lexical.token;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author ISJINHAO
 * @Date 2021/2/23 15:07
 */
public class KeyWords {

    private KeyWords() {
    }

    private static KeyWords instance = new KeyWords();

    public static KeyWords getInstance() {
        return instance;
    }

    private static final Map<String, TokenType> keywords;

    /**
     * union、minus、intersect、except、select、distinct、first、last、as、
     * avg、max、min、count、sum、flat、from、left、right、join、where、and、
     * or、not、exists、in、like、group、by、having、order、desc、asc、limit、
     * is、null、case、when、else、end、true、false
     */
    static {
        keywords = new HashMap<>();
        keywords.put("union", TokenType.CUNION);
        keywords.put("minus", TokenType.CMINUS);
        keywords.put("intersect", TokenType.CINTERSECT);
        keywords.put("except", TokenType.CEXCEPT);
        keywords.put("select", TokenType.SELECT);
        keywords.put("distinct", TokenType.DISTINCT);
        keywords.put("first", TokenType.FIRST);
        keywords.put("last", TokenType.LAST);
        keywords.put("as", TokenType.AS);
        keywords.put("avg", TokenType.AVG);
        keywords.put("max", TokenType.MAX);
        keywords.put("min", TokenType.MIN);
        keywords.put("count", TokenType.COUNT);
        keywords.put("sum", TokenType.SUM);
        keywords.put("flat", TokenType.FLAT);
        keywords.put("from", TokenType.FROM);
        keywords.put("left", TokenType.LEFT);
        keywords.put("right", TokenType.RIGHT);
        keywords.put("outer", TokenType.OUTER);
        keywords.put("join", TokenType.JOIN);
        keywords.put("on", TokenType.ON);
        keywords.put("where", TokenType.WHERE);
        keywords.put("and", TokenType.AND);
        keywords.put("or", TokenType.OR);
        keywords.put("not", TokenType.NOT);
        keywords.put("exists", TokenType.EXISTS);
        keywords.put("in", TokenType.IN);
        keywords.put("like", TokenType.LIKE);
        keywords.put("by", TokenType.BY);
        keywords.put("having", TokenType.HAVING);
        keywords.put("order", TokenType.ORDER);
        keywords.put("desc", TokenType.DESC);
        keywords.put("asc", TokenType.ASC);
        keywords.put("limit", TokenType.LIMIT);
        keywords.put("is", TokenType.IS);
        keywords.put("null", TokenType.NULL);
        keywords.put("case", TokenType.CASE);
        keywords.put("when", TokenType.WHEN);
        keywords.put("else", TokenType.ELSE);
        keywords.put("end", TokenType.END);
        keywords.put("true", TokenType.TRUE);
        keywords.put("false", TokenType.FALSE);
        keywords.put("group", TokenType.GROUP);
        keywords.put("date_to_timestamp", TokenType.DATE_TO_TIMESTAMP);
        keywords.put("date_to_str", TokenType.DATE_TO_STR);
        keywords.put("str_to_date", TokenType.STR_TO_DATE);
        keywords.put("str_to_timestamp", TokenType.STR_TO_TIMESTAMP);
        keywords.put("timestamp_to_date", TokenType.TIMESTAMP_TO_DATE);
        keywords.put("timestamp_to_str", TokenType.TIMESTAMP_TO_STR);
        keywords.put("now", TokenType.NOW);
        keywords.put("into", TokenType.INTO);
        keywords.put("insert", TokenType.INSERT);
        keywords.put("update", TokenType.UPDATE);
        keywords.put("values", TokenType.VALUES);
        keywords.put("set", TokenType.SET);
        keywords.put("delete", TokenType.DELETE);
        keywords.put("ignore", TokenType.IGNORE);
        keywords.put("duplicate", TokenType.DUPLICATE);
        keywords.put("key", TokenType.KEY);
    }

    public TokenType get(String keyWord) {
        return keywords.get(keyWord);
    }

    public static void main(String[] args) {
        System.out.println(keywords.size());
    }

}
